<?php
/**
 * Created by PhpStorm MK_AC-1004-儿童节问卷调查
 * User: allen.qiang
 * Date: 2015-03-20
 * Time: 上午10:00
 */
quanli_require('module/base/activity/activityConfig.class.php');
quanli_require('module/base/customer/quanliCust.class.php');
//加载会员促销类
quanli_include('module/base/promotion/promotionCustomer.class.php');

class activityQuestionnaire {

    public $configName="Questionnaire";//activities_extend表活动编号

    /**
     * 问卷信息收集
     * $Mobile 手机号
     * $arg_array_list 问卷答题信息数组
     * @author  2015-03-20 allen.qiang <allen.qiang@fistforward.com>
     */
    public  function get_activities_extend($Mobile,$arg_array_list) {
        global $G_SHOP;

        try{
            $G_SHOP->DBCA->beginTransaction();

            $sql="SELECT COUNT(1) AS item_count FROM `activities_extend` WHERE activityNumber='".$this->configName."' AND classifyID=?";
            $item_master = &$G_SHOP->DBCA->stmt_query($sql,'s',$Mobile);
            if($item_master && $item_master[0]->item_count>0){
                $G_SHOP->DBCA->commit();
                return array( 'code' => 700, 'message' => '该手机号已提交过问卷<br>一个手机号只能提交一次哦！' );
            }else{
                foreach($arg_array_list as $arg_array)
                {
                    //保存答卷内容
                    $activities_extend = new entity('activities_extend');
                    $activities_extend->creator = $Mobile; //创建人
                    $activities_extend->activityNumber = $this->configName; //活动编号
                    $activities_extend->classifyID =$Mobile; //手机号
                    $activities_extend->extend_1 = $arg_array["Topic_No"]; //题号
                    $activities_extend->extend_4 = $arg_array["Topic_Type"]; //题目类型 1：单选；2：填空
                    $activities_extend->extend_5 = $arg_array["Answer_Type"]; //答案分类 为空表示没有分类答案
                    $activities_extend->extend_9 = $arg_array["Answer_Content"]; //答案内容
                    if (!$G_SHOP->DBCA->save($activities_extend)) {
                        throw new Exception('页面已过期，请刷新页面重试', 404);
                    }
                    //检查用户是否存在
                  /*  $args_array = array(
                        'custID' =>$Mobile
                    );
                    $quanliCust = new quanliCust();
                    $customer_array = $quanliCust->searchCustomerDetail( $args_array );

                    if ($customer_array) { //会员送1000积分
                        //实例会员促销类
                        $promotionHandler = new promotionCustomer();
                        //查询会员促销活动并发放
                        $promotionHandler->grantCustPromotion( $customer_array["pcustID"], $customer_array["custID"], 5 );
                    }*/
                }

                $G_SHOP->DBCA->commit();
                return array( 'code' => 200, 'message' => '您的答卷已提交，感谢您的参与！' );
            }

        }
        catch (Exception $e) {

            $G_SHOP->DBCA->rollBack();

            if ($e->getCode() > 0)
                return array( 'code' => $e->getCode(), 'message' => $e->getMessage() );
            else {
                error_log($e->getMessage());
                return array( 'code' => 700, 'message' => '系统错误' );
            }
        }
    }

} 